// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#ifndef __H_MK_D3D9_TEXTURE__
#define __H_MK_D3D9_TEXTURE__

#include "mk_texture.h"
#include "mk_render_define.h"

namespace MK3DE
{
	class CD3D9Texture2D : public CTexture2D
	{
	public:
		CD3D9Texture2D();
		CD3D9Texture2D(const char* fileName);
		virtual ~CD3D9Texture2D();

	public:
		BOOL Load();
		BOOL LoadFromBuffer(const BYTE* buffer, DWORD size);
		BOOL Create(DWORD width, DWORD height, PIXEL_FORMAT format, DWORD mip, TEXTURE_USAGE usage);

		BOOL LockRect(void** pData, DWORD* pitch, RECT* pRect);
		BOOL Unlock();

		DWORD GetWidth() { return _width; }
		DWORD GetHeight() { return _height; }

		DWORD GetOriginalWidth() { return _imageInfo.Width; }
		DWORD GetOriginalHeight() { return _imageInfo.Height; }

		BOOL IsRenderTarget() { return _usage == TU_RENDER_TARGET ? TRUE : FALSE; }

		PIXEL_FORMAT GetFormat() { return _format; }

		BOOL SaveToFile(const char* fileName);

		BOOL GetRenderTargetSurface(LPDIRECT3DSURFACE9& surface);
		LPDIRECT3DTEXTURE9 GetD3D9Texture() { return _texture; }

	private:
		void __MappingUsage(DWORD& d3dusage, D3DPOOL& pool, TEXTURE_USAGE usage);
		BOOL __GetLockFlag(DWORD& flag);
		void __ObtainActualTextureSize();

	private:
		LPDIRECT3DTEXTURE9  _texture;

		DWORD           _width;
		DWORD           _height;
		DWORD           _mip;
		PIXEL_FORMAT    _format;
		TEXTURE_USAGE   _usage;

		D3DXIMAGE_INFO  _imageInfo;
	};

	class CD3D9Texture3D : public CTexture3D
	{
	public:
		CD3D9Texture3D();
		CD3D9Texture3D(const char* fileName);
		virtual ~CD3D9Texture3D();

	public:
		BOOL Load();

		LPDIRECT3DVOLUMETEXTURE9 GetD3D9Texture() { return _texture; }

	private:
		LPDIRECT3DVOLUMETEXTURE9    _texture;

		D3DXIMAGE_INFO  _imageInfo;
	};
};

#endif // __H_MK_D3D9_TEXTURE__